Bug 164068 - $HOME in working direcotry not expanded when running a program shortcut
Summary: $HOME in working direcotry not expanded when running a program shortcut
Status: RESOLVED FIXED
Alias: None
Product: kdelibs
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-06-14 16:15 UTC by Ambroz Bizjak
Modified: 2009-11-14 01:04 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
patch to kdelibs, fixes properties dialog (944 bytes, patch)
2008-06-23 17:07 UTC, Ambroz Bizjak
Details
kdelibs patch, adds use of X-KDE-Path (4.85 KB, patch)
2008-06-26 14:21 UTC, Ambroz Bizjak
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ambroz Bizjak 2008-06-14 16:15:51 UTC
Version:            (using Devel)
Installed from:    Compiled sources
Compiler:          gcc (GCC) 4.1.2 (Gentoo 4.1.2 p1.1) 
OS:                Linux

When I click on a program shortcut, $HOME in the working directory (Path[$e]) is not expanded and leads to the wrong working directory being used. This is contrary to the shortcut editor (Properties on a .desktop file), which automatically translates my home in the working directory to $HOME. Other desktops properly handle $HOME including KDE3.
Comment 1 Ambroz Bizjak 2008-06-23 17:06:49 UTC
Just realised it was KDE which changed my .desktop shortcuts from using full path in 'Path' to substituting /home/user with $HOME in the Properties dialog. In fact ONLY KDE3 seems to understand such notation, e.g. Gnome will fail to recognize "Path=$HOME/something" and only works with absolute paths.

So I guess KDE complies with the standards for not understanding such notation. The patch I am attaching fixes the Properties dialog to always use full path when modifying a shortcut.

However shortcuts previously modified with KDE3/KDE4 will still have Path broken.
Comment 2 Ambroz Bizjak 2008-06-23 17:07:38 UTC
Created attachment 25543 [details]
patch to kdelibs, fixes properties dialog
Comment 3 Aaron J. Seigo 2008-06-23 22:26:20 UTC
this patch will break roaming profiles, and as suck is incorrect. the real fix is to expand $HOME properly (by reading it as a path entry from the config) where ever the launching is happening. this is a pretty snaky path inside of kdelibs; and just to confirm: if you use a working path without $HOME in it, does it work properly?
Comment 4 Ambroz Bizjak 2008-06-23 23:35:53 UTC
The relevant code is in kdelibs/kdecore/config/kdesktopfile.cpp line 195:

QString KDesktopFile::readPath() const
{
  Q_D(const KDesktopFile);
  // NOT readPathEntry, it is not XDG-compliant. Path entries written by
  // KDE4 will be still treated as such, though.
  return d->desktopGroup.readEntry("Path", QString());
}

Well it does not look like they are treated as such. I guess replacing that with readPathEntry will fix it.
Comment 5 Ambroz Bizjak 2008-06-23 23:36:36 UTC
and yes, it does work by entering the full path with a text editor.
Comment 6 Ambroz Bizjak 2008-06-26 08:49:26 UTC
Has anything been done about this issue?
Basically, we can either change that function to use readPathEntry, disobeying the standards and breaking the path for compliant DEs (same as KDE3), however allowing roaming profiles,
or leave the runner part compliant, fix the Properties dialog to be consistent with the runner, and by that allow the shortcuts to work with other DEs, however breaking roaming profiles.

Another option would be to still be compliant, but use a KDE-private field that would allow the shortcut to work with roaming profiles in KDE. Something like Path=/home/user163/some/folder and X-KDE-UseMyHomeInPath=yes, that would tell the runner to substitute /home/* with the current user's home folder.
Comment 7 Ambroz Bizjak 2008-06-26 14:21:56 UTC
Created attachment 25619 [details]
kdelibs patch, adds use of X-KDE-Path

I have created a patch that fixes the issue by introducing a new variable,
X-KDE-Path that uses the notation supporting roaming profiles.

I have changed KDesktopFile::readPath to be smarter:
it first checks if Path is non-standard and reads it appropriately. Then it
checks for X-KDE-Path, reads it using KConfigGroup::readPathEntry and compares
the fully expanded paths. If X-KDE-Path started with $HOME/ (or is $HOME) and
the only difference is the name of the home folders (roaming profile, user name
changed), it returns the expanded X-KDE-Path, otherwise Path.

The properties dialog now uses the the same readPath routine as the runner
does, and when writing the changes, it writes X-KDE-Path in the portable
notation, and Path in the same format as it was before (thereby not breaking
roaming profiles for KDE3).
Comment 8 David Faure 2008-06-26 18:12:51 UTC
The right solution is to get the Desktop Entry Standard to support env vars.
Mail posted to the xdg list on freedesktop.org today.
Comment 9 David Faure 2008-06-26 18:15:20 UTC
SVN commit 824757 by dfaure:

For now, let's be consistent with kservice.cpp, so that things work even if breaks roaming.
CCBUG: 164068


 M  +2 -2      kpropertiesdialog.cpp  


WebSVN link: http://websvn.kde.org/?view=rev&revision=824757
Comment 10 FiNeX 2009-11-02 13:21:46 UTC
@David: does that patch fix this bug?
Comment 11 David Faure 2009-11-14 01:04:51 UTC
I guess so, since this bug report wasn't about roaming being broken, so it basically works now for the use case described here (right Ambroz? please reopen if not).

Didn't get much out of xdg list btw, just some vague interest and concerns; ping'ed again today.