On Sat, 4 Feb 2012 at 0:36:50 +0100, Rodolfo kix Garcia wrote:
>
> Subject: [PATCH] WindowMaker: Support for icons from .desktop files
Very nice patch!
> +/* Returns the icon file patch from a .desktop file */
> +WMPropList *get_iconpath_from_desktop_file(char *classe)
I think it would be better to use the english word 'class'
> +/* This function returns the Icon defined in a .desktop file */
> +char *get_iconname_from_desktopfile(char *desktopfile)
> +{
> + FILE *dt = NULL;
> + char *iconline = NULL;
> + char *iconname = NULL;
> + char linebuf[MAXLINE];
> + int i, j, hasdot, hasslash;
> +
> + /* If .desktop file name is null, return */
> + if (!desktopfile)
> + return NULL;
> +
> + /* Open the .desktop file */
> + dt = fopen(desktopfile, "rb");
The above two comments can be dropped, as the code is self-documenting.
> + if (!dt) {
> + werror(_("%s:could not open desktop file"), desktopfile);
Wouldn't
"could not open desktop file %s"
be better to read? werror already prints a lot of leading informationn.
> + return NULL;
> + }
> +
> + /* Search the "Icon" line in the file an save it */
> + iconline = wmalloc(MAXLINE);
> + while (!feof(dt)) {
> + if (!fgets(linebuf, MAXLINE - 1, dt))
> + break;
> +
> + /* Found, save it */
> + if (!strncmp(linebuf, "Icon", 4)) {
> + snprintf(iconline, MAXLINE - 1, "%s", linebuf);
> + break;
> + }
> + }
> + /* Close the file */
> + fclose(dt);
Drop comment
> +/* This function returns the full patch of the icon
> + * The value in the .desktop file can have these problems:
> + * 1. No fullpath: "ddd.xpm"
> + * 2. No extension "ddd" or "/path/ddd"
> + * For 1, the possible paths (in order) are:
> + * - $HOME/.icons
> + * - $XDG_DATA_DIR/icons
The specification says it is XDG_DATA_DIRS (mind the S at the end)
And I just tested here, using XDG_DATA_DIR returns null, whereas
XDG_DATA_DIRS give my /usr/share
> + * - /usr/share/pixmaps
> + * For 2, possible extensions are (in order):
> + * - .png (required, in lowercase!)
> + * - .xpm (required, in lowercase!)
> + * - .svg (optional, not supported by wmaker) */
> +char *get_correct_path(char *fp)
> +{
> + struct stat dummy;
> + int y, z;
> + char *tmp, *homedir, *xdgdir, *pixdir;
> + char *paths[3];
> + char *extensions[2] = { "png", "xpm" };
> + char *toret = NULL;
> + int i = 0;
> +
> + if (!fp)
> + return NULL;
> +
> + /* Don't spend time; Full path? Test it! */
> + if (stat(fp, &dummy) > 0) {
> + toret = wstrdup(fp);
> + return toret;
> + }
> +
> + /* Read the $HOME, don't use wgethomedir() */
> + tmp = getenv("HOME");
> + if (tmp) {
> + homedir = wmalloc(strlen(tmp) + 8);
> + sprintf(homedir, "%s/.icons", tmp);
> + if (stat(homedir, &dummy) >= 0) {
> + paths[i] = homedir;
> + i++;
> + }
> + }
> +
> + /* Read $XDG_DATA_DIR */
> + tmp = getenv("XDG_DATA_DIR");
XDG_DATA_DIRS
> + if (tmp) {
> + xdgdir = wmalloc(strlen(tmp) + 1);
> + sprintf(xdgdir, "%s", tmp);
> + if (stat(xdgdir, &dummy) >= 0) {
> + paths[i] = xdgdir;
> + i++;
> + }
> + }
--
To unsubscribe, send mail to [email protected].