Bug 225255 - KConfig does not deliver the correct result when using [$e] modifier and default values
Summary: KConfig does not deliver the correct result when using [$e] modifier and defa...
Status: CONFIRMED
Alias: None
Product: kdelibs
Classification: Frameworks and Libraries
Component: kdecore (show other bugs)
Version: 4.3
Platform: openSUSE Linux
: NOR normal
Target Milestone: ---
Assignee: kdelibs bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-02-02 12:21 UTC by Jörg Steffens
Modified: 2010-03-07 11:53 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments
test program for the describted behaviour (3.15 KB, application/x-compressed-tar)
2010-02-02 12:25 UTC, Jörg Steffens
Details
NoDisplay=False (291 bytes, application/x-desktop)
2010-02-02 16:13 UTC, Jörg Steffens
Details
NoDisplay=True (289 bytes, application/x-desktop)
2010-02-02 16:14 UTC, Jörg Steffens
Details
NoDisplay[$e]=$(echo False) (295 bytes, application/x-desktop)
2010-02-02 16:18 UTC, Jörg Steffens
Details
TestProgram in C++ (1.86 KB, text/x-c++src)
2010-02-09 12:16 UTC, Holger Müller
Details
Patch / Workaround to let DesktopFile NoDisplay setting work with expand feature (584 bytes, patch)
2010-03-03 16:40 UTC, Holger Müller
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jörg Steffens 2010-02-02 12:21:35 UTC
Version:            (using KDE 4.3.1)
Compiler:           orig openSUSE 11.2 RPM, i586
OS:                Linux
Installed from:    openSUSE RPMs


when working with default values and the execute [$e] modifier in KDE Desktop files,
KConfig delivers different results.
Comment 1 Jörg Steffens 2010-02-02 12:25:13 UTC
Created attachment 40457 [details]
test program for the describted behaviour
Comment 2 Jörg Steffens 2010-02-02 12:46:24 UTC
how to reproduce:
download test environment from Comment 1

tar -xvzf kreadconfig.tgz
cd kreadconfig
./kread-desktopfile-test.sh

Result on my system is:
filename:                         testdir/test.desktop
readName():                       TEST root           
readEntry( "Name" ):              TEST root           
readEntry( "Name", "default" ):   $(echo TEST $USER)  
icon:                             xmag                
noDisplay():                      True                
readEntry( "NoDisplay" ):         False               
readEntry( "NoDisplay", True ):   true
readEntry( "NoDisplay", False ):  true

dump:
[Desktop Entry]
Categories = X-SuSE-DesktopUtility;
Encoding = UTF-8
Exec = xmag
GenericName = Desktop Magnifier
Icon = xmag
Name = TEST root
NoDisplay = False
Type = Application
X-KDE-StartupNotify = false
X-SuSE-Unimportant = true
X-SuSE-translate = true

Explanation:
The test program sets KDEDIRS=$PWD/test/profile1
The Desktop-File test/profile1/share/applnk/testdir/test.desktop is evaluated.
The important entries are:
Name[$e]=$(echo TEST $USER)
NoDisplay[$e]=$(echo "X" >> /tmp/kde.log; echo False)

Name should result in "TEST root" (when called as root)
and (more important) NoDisplay should result into "False".

I've used this (with Hidden instead of NoDisplay) in KDE3,
to make an applications only visible if a specific file exists (eg. show application only in start menu if its config file exists)

Maybe, this bug is also related to https://bugs.kde.org/show_bug.cgi?id=197523
which have been solved on the application site instead of KConfig.
Comment 3 Oswald Buddenhagen 2010-02-02 14:29:02 UTC
it would be helpful if you provided a minimal sample, without all the python indirections (i.e., a c++ program, preferably in form of a new testcase in the kconfig autotest. or alternatively a shell script which just uses kreadconfig4).
Comment 4 Jörg Steffens 2010-02-02 16:13:45 UTC
Created attachment 40463 [details]
NoDisplay=False
Comment 5 Jörg Steffens 2010-02-02 16:14:24 UTC
Created attachment 40464 [details]
NoDisplay=True
Comment 6 Jörg Steffens 2010-02-02 16:18:17 UTC
Created attachment 40465 [details]
NoDisplay[$e]=$(echo False)
Comment 7 Jörg Steffens 2010-02-02 16:18:38 UTC
sorry, I'm afraid I'm not able to do this. I'm not very skilled at C++ and KDE programming.
And kreadconfig is very limited. It is primarily intended for config, not desktop files. And when I use it with full path filename, it presents the correct results.

But I can provide another test case without further dependencies.
I'll add three desktop files as attachments. They are identical, except the NoDisplay entry:
1. NoDisplay=False
2. NoDisplay=True
3. NoDisplay[$e]=$(echo False)

copy them to your xdg-data-apps path (eg. /usr/share/applications/).
1 and 3 should get visible in the start menu. Unfortunally, this does not happen for test3:
test1: is visible (correct)
test2. is not visible (correct)
test3. is not visible (wrong!)
Comment 8 Holger Müller 2010-02-09 12:10:18 UTC
It seems, that the problem occours in KConfigGroup::readEntry with a boolean default value. This is what KDesktopFile::noDisplay calls.
I don't find a way to evalute to a false value if expand 
[$e] is used in Config files.

I've set $foo to "false" in environment and set NoDisplay[$e]=$foo
in a test Desktopfile

    const KConfigGroup group = kdf.group("Desktop Entry");

    qDebug() << "readEntry ( \"NoDisplay\", true ): " <<
            group.readEntry("NoDisplay", true);
    qDebug() << "readEntry ( \"NoDisplay\", false ): " <<
            group.readEntry("NoDisplay", false);
    qDebug() << "readEntry ( \"NoDisplay\", \"false\" ): " <<
            group.readEntry("NoDisplay", "false");

readEntry ( "NoDisplay", true ):  true
readEntry ( "NoDisplay", false ):  true
readEntry ( "NoDisplay", "false" ):  "false"

So it seems impossible to use the expand feature for boolean values.
I consider this as a bug.

Regards Holger
Comment 9 Holger Müller 2010-02-09 12:16:20 UTC
Created attachment 40613 [details]
TestProgram in C++

specify desktop file via the -f option.

# CMakeLists.txt 
project (kde4profile)
find_package(KDE4 REQUIRED)
include (KDE4Defaults)
include_directories(${KDE4_INCLUDES})
set(kde4profile_SRCS kde4profile.cpp)
kde4_add_executable(kde4profile ${kde4profile_SRCS})
target_link_libraries(kde4profile ${KDE4_KDEUI_LIBS})
install(TARGETS kde4profile ${INSTALL_TARGETS_DEFAULT_ARGS})

# test.desktop
[Desktop Entry]
X-SuSE-translate=true
X-SuSE-Unimportant=true
Categories=X-SuSE-DesktopUtility;
Encoding=UTF-8
Exec=xmag
Type=Application
Name[$e]=$foo
NoDisplay[$e]=$foo
GenericName=Desktop Magnifier
Icon[$e]=$foo
X-KDE-StartupNotify=false
Comment 10 Holger Müller 2010-02-11 14:40:20 UTC
This bug is a result of bug > 226314.
But if there is no solution for 226314 it would be
possible to change 
kdesktopfile.cpp:

bool KDesktopFile::noDisplay() const
{
    Q_D(const KDesktopFile);
    if (d->desktopGroup.readEntry("NoDisplay", false)) {
        return true;
    }
...

to

if (QString("false").compare(d->desktopGroup.readEntry("NoDisplay", "false")) == 0)
Comment 11 Holger Müller 2010-03-03 16:40:02 UTC
Created attachment 41291 [details]
Patch / Workaround to let DesktopFile NoDisplay setting work with expand feature

Workaround checked against OpenSUSE 11.2 Update Sources (4.3.5)
Comment 12 Oswald Buddenhagen 2010-03-07 11:53:16 UTC
so i had a look at the code and deep into my memory ... the expansion stuff is an utter mess, and fixing it is in fact the first item in the TODO file.