After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 139974 - a .desktop file parser
a .desktop file parser
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: general
2.5.x
Other Linux
: Normal enhancement
: ---
Assigned To: gtkdev
gtkdev
Depends on: 139971 139973
Blocks:
 
 
Reported: 2004-04-13 21:14 UTC by Ray Strode
Modified: 2011-02-18 16:09 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
.desktop file parsing functions (54.21 KB, patch)
2004-04-13 21:16 UTC, Ray Strode
needs-work Details | Review
Desktop Entry File Parser (113.67 KB, patch)
2004-10-18 04:16 UTC, Ray Strode [halfline]
none Details | Review

Description Ray Strode 2004-04-13 21:14:14 UTC
.desktop files are an important part of most applications now.  It would be
useful if glib provided a means for saying "this .desktop file belongs to this
program".  Then it could automatically determine the application name from the
.desktop file, and higher level libraries could use other information from the
.desktop file (for instance gtk+ could set the application icon, etc).
Comment 1 Ray Strode 2004-04-13 21:16:51 UTC
Created attachment 26635 [details] [review]
.desktop file parsing functions

The attached patch provides functions for parsing .desktop files as well as
functions for associating a .desktop file with an application.	Note this patch
depends on the patches in bug 139971 and bug 139973.
Comment 2 Ray Strode [halfline] 2004-06-16 21:14:56 UTC
Note this is sitting in libegg now with fixes and api improvements as
libegg/desktopentries

Still needs more testing and fixed documentation, though.
Comment 3 Ray Strode [halfline] 2004-07-27 20:22:08 UTC
Discussion with Anders has lead to the following tasks:

- change egg_desktop_entries_ to g_desktop_entry_
- make parse_data and flush_parse_buffer static
- add from_data constructor
- make add_entry and add_group static
- provide set methods that mirror the get methods
  (which would called add_entry and add_group under the hood)
- make new_from_file not search $XDG_DATA_DIRS by default
  and provide g_desktop_entry_new_from_data_dirs for 
  searching from $XDG_DATA_DIRS.
Comment 4 Matthias Clasen 2004-08-26 00:45:55 UTC
Comment on attachment 26635 [details] [review]
.desktop file parsing functions

Ray, did you ever produce an updated patch ?
Comment 5 Ray Strode [halfline] 2004-08-27 05:27:57 UTC
I've updated the code in libegg.  Over the weekend I'll pull the code from
libegg and produce a patch applyable to glib.
Comment 6 Ray Strode [halfline] 2004-10-18 04:16:29 UTC
Created attachment 32715 [details] [review]
Desktop Entry File Parser

This is the latest incarnation of the Desktop Entry parser.  It uses some
rather new glib apis, including g_get_*_data_dirs() and g_get_language_names()
Comment 7 Matthias Clasen 2004-10-18 16:53:38 UTC
Notes from a very quick discussion with owen:

- a lot of code, 3000 lines
- having some unit tests would be very nice
- we have a ~1000 line parser for .icon files which also use
  the .ini file syntax and have things like localized string lists.
  it would be very nice, if it was possible to make gtk+ use the
  new glib code for its .ini file parsing needs
Comment 8 Ray Strode [halfline] 2004-10-18 17:36:21 UTC
- it is a fairly sizable chunk of code, but on the other hand it has had a
reasonable amount of testing and bugfixes because the libegg code is used by
gnome-vfs and desktop-file-utils.

- unit tests would definitely be a good idea.  It may take a while for me to
write a good complete set of tests, however.

- jrb mentioned the .icon parser to me before and I think it would be a very
good idea to switch it over, rather than keeping duplicate functionality in the
library  stack.
Comment 9 Matthias Clasen 2004-10-18 19:08:23 UTC
So it turns out that what we are actually adding here is not a desktop entry
parser, but rather a generic parser for the ini file format (possibly with some 
restrictions/extension compared to the "true" win32 ini format). I think it
would be a good idea to make this clear by renaming the api to something more
generic, e.g g_config_... or g_ini_file_...
Comment 10 Matthias Clasen 2004-10-19 19:32:49 UTC
I think it would be good to remove the special casing of legal_start_groups ==
NULL, which is currently tailored towards desktop entries. Instead, I would
propose to let legal_start_groups == NULL mean that there is no restriction. 
For parsing desktop entries, one would then have to set the legal start groups
explicitly.
Comment 11 Ray Strode [halfline] 2004-10-19 22:34:24 UTC
Discussion from gtk team meeting:
- Name should be GKeyFile
- While the format is similiar to .ini files, it does have some significant
differences (comment syntax, translated keys, etc), so it shouldn't aim to
support .ini files.
- legal_start_groups stuff should be removed.  If the user of the API cares what
the first group is they can call get_groups and look.
- Legacy/Mixed encoding support should be removed.  It adds significant
complexity and a seldom-used code path.
- should default to discarding comments and translations to optimize for the
read case which is the most common.
- should drop the new_from_file and new_from_data constructors and add
load_from_file and load_from_data functions
- should remove GError's from the setters--they can't fail.
Comment 12 Ray Strode [halfline] 2004-10-22 16:09:49 UTC
More discussion led to:

- Don't escape tabs and spaces in the middle of values
    . Still need to escape spaces and tabs at the beginning and end of values
    . Should probably escape newline and carriage return regardless of where
      they are in the string

- set_value and get_value were made static in favor of an escape_strings on/off 
  toggle function.  That change should be reverted.

- The latest version of the desktop entry specification supports escaping ; 
  for lists with \;

- Provide method for specifying list delimiter because icon theme spec uses , 
  instead of ;
Comment 13 Matthias Clasen 2004-10-23 06:24:05 UTC
I committed my latest version, which incorporates all the recent discussion.