GNOME Bugzilla – Bug 527304
Allow for drop-in applications files
Last modified: 2008-07-15 22:06:19 UTC
It would be useful for 3rd party applications to be able to add themselves to the list of preferred applications. In this case, a 3rd-party repository wants to add mplayer to the list: https://bugzilla.redhat.com/show_bug.cgi?id=441587
Sounds like a candidate for gnome-love. You can look at the keybindings capplet which works with modular configuration files in a similar way.
Created attachment 114354 [details] [review] Adds processing of additional application specification files, allowing third party applications to register themselves
I've created a patch to fix this. (I'm also happy that there was an existing bug for this, so I'm not alone. Currently, I've added code to load any files found in $GNOMECC_DATA_DIR/default-apps, in addition to the normal defaults. I didn't add any extra validation of the files, as that should be taken care of by the existing functions. The end result is that a third-party maintainer can drop an XML file (of the same format as gnome-default-applications.xml) into /usr/share/gnome-control-center/default-apps and have their application appear in the dropdown for preferred applications. This (as well as the existing solution) strikes me as something of a hack, as URL handlers really should be handled the same way as file handlers, but until the freedesktop "standard" is extended to handle URI schemes as well as MIME types, this will have to do.
Thanks for your patch. A few comments: @@ -296,6 +299,20 @@ if (capplet->web_browsers == NULL) gnome_da_xml_load_xml (capplet, "./gnome-default-applications.xml"); + + dirname = g_build_filename (GNOMECC_DATA_DIR, "default-apps", NULL); + app_dir = g_dir_open(dirname, 0, NULL); Please use the same coding style as the rest of the code, ie. put a space before the opening brace, + if (app_dir != NULL) { + while ((extra_file = g_dir_read_name(app_dir)) != NULL) { + filename = g_build_filename (dirname, + extra_file, + NULL); + g_print("%s\n", filename); Looks like you forgot some debug spew. + gnome_da_xml_load_xml (capplet, filename); It might also be a good idea to check for a proper suffix on the file before trying to parse it. + } And you're leaking the file descriptor. + } + g_free(dirname); } And finally, you should add the directory to the pkg-config .pc file so that other applications can figure out where to dump their files (plus, we should move the file with the defaults there as well).
Created attachment 114623 [details] [review] Updated path Fixed a few memory leaks, added file extension checking. Did not patch .pc file because there isn't one yet and I or somebody else can create that as a separate patch.
The new patch still needed some fixing wrt coding style and resource cleanup but I have committed it now. Thanks. I have also added the pc file and moved the default file list.